package com.asianrapid.controller.sys;

import com.asianrapid.model.sys.LqrzEntity;
import com.asianrapid.model.sys.PageResult;
import com.asianrapid.service.sys.LqrzService;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class LqrzController {
    private Logger log = LoggerFactory.getLogger(LqrzController.class);
    @Autowired
    private LqrzService lqrzService;

    @GetMapping("/getlqrz")
    public PageResult getall(int pageSize, int page) {
        PageResult pageResult = new PageResult();
        List<LqrzEntity> list = lqrzService.getalllqrj(pageSize, page);
        int total = lqrzService.getCount();
        pageResult.setTotalCount(total);
        pageResult.setData(list);
        return pageResult;
    }

    @PostMapping("/insertlqrz")
    public void insert(@RequestBody LqrzEntity lqrzEntity) {
        lqrzService.insertlqrzf(lqrzEntity);
        int i = lqrzService.findlqrint(lqrzEntity);
        lqrzEntity.setMan(String.valueOf(i));
        lqrzService.insertlqrz(lqrzEntity);
    }

    @PutMapping("/updatelqrz")
    public LqrzEntity update(@RequestBody LqrzEntity lqrzEntity) {
        lqrzService.updatelqrz(lqrzEntity);
        String list = lqrzEntity.getMan();
        lqrzService.updatelqrzf(lqrzService.findman(lqrzEntity.getId()), list);
        return lqrzEntity;
    }

    @PostMapping("/loadz")
    public LqrzEntity load(@RequestBody List<Integer> groupId) {
        return lqrzService.load(groupId.get(0));
    }

    @DeleteMapping("/deletelqrz")
    public List<String> deletelqrz(@RequestBody List<String> groupId) {
        lqrzService.deletelqrz(groupId);
        return groupId;
    }
}
